package lettcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec lettcode
 * @since 2023-07-08 17:05
 */
public class Main {
    public static void main(String[] args) {
        String res = new Main().longestPalindrome("a");
        System.out.println(res);
    }
    public String longestPalindrome(String s) {
        int maxLen = 0, start = 0;
        int len;
        for(int i = 0; i < s.length(); i++){
            len = getLen(s, i, i) - 1;
            if(len > maxLen){
                maxLen = len;
                start = i - len/2;
            }
            len = getLen(s, i, i + 1);
            if(len > maxLen){
                maxLen = len;
                start = i - len/2 + 1;
            }
        }
        return s.substring(start, start + maxLen);
    }
    public int getLen(String s, int left, int right){
        int cnt = 0;
        while(left >= 0 && right < s.length()){
            if(s.charAt(left--) != s.charAt(right++)){
                return cnt;
            }
            cnt += 2;
        }
        return cnt;
    }
}
